<template>
  <!-- 搜索栏部分 -->
  <el-card class="search-card">
    <el-form :model="searchForm" label-width="80px" inline>
      <el-form-item label="供应商编码">
        <el-input v-model="searchForm.code" placeholder="供应商编码" clearable />
      </el-form-item>
      <el-form-item label="供应商名">
        <el-input v-model="searchForm.name" placeholder="供应商名" clearable />
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="searchForm.status" style="width:100px" placeholder="请选择状态" clearable>
          <el-option label="启用" value="1" />
          <el-option label="禁用" value="0" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handlerSearch">搜索</el-button>
        <el-button @click="resetSearch">重置</el-button>
      </el-form-item>
    </el-form>
  </el-card>
  <!-- 列表 -->
  <el-card class="table-card">
    <el-radio-group v-model="selectedSupplierCode" style="width: 100%">
    <el-table
        :data="supplierList"
        border
        stripe
    >
      <el-table-column>
        <template #default="scope">
          <el-radio :value="scope.row.code"/>
        </template>
      </el-table-column>
      <el-table-column prop="code" label="供应商编号" />
      <el-table-column prop="name" label="供应商名" />
      <el-table-column prop="address" label="供应商地址" />
      <el-table-column prop="contactPerson" label="联系人" />
      <el-table-column prop="phone" label="联系电话" />
      <el-table-column prop="status" label="状态" width="80">
        <template #default="scope">
          <el-tag :type="scope.row.status == '1' ? 'success' : 'danger'">
            {{ scope.row.status == '1' ? '启用' : '禁用' }}
          </el-tag>
        </template>
      </el-table-column>
    </el-table>
    </el-radio-group>
  </el-card>
  <el-row style="margin: 40px">
    <el-button @click="doSelectSupplier">确定</el-button>
  </el-row>
</template>

<script setup>
//导入

//----------属性申明 ⬇
import {ref,onMounted} from "vue";
import {getSupplierPage} from "@/api/supplier.js";
//查询表单
const searchForm = ref({
  code:"",
  name:"",
  status:""
})
//数据展示列表
const supplierList = ref([])
//返回数据
const selectedSupplierCode = ref(-1);
//申明返回事件
const emit = defineEmits(["selectSupplier"]);
//----------属性申明 ⬆
//-----------函数申明 ⬇
//搜索列表
const handlerSearch = ()=>{
  getSupplierPage(1, 1000, searchForm.value).then(res=>{
    supplierList.value = res.data.list;
  })
}
//重置查询列表
const resetSearch = ()=>{
  searchForm.value = {
    code:"",
    name:"",
    status:""
  }
}
const doSelectSupplier = ()=>{
  emit("selectSupplier",selectedSupplierCode.value)
}
//加载数据
onMounted( ()=>{
  handlerSearch();
})
//------------函数申明 ⬆

</script>

<style scoped>

</style>